package com.qs.provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qs.common.entity.Faqs;
import com.qs.common.service.FaqsService;
import com.qs.common.util.Condition;
import com.qs.provider.mapper.FaqsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,timeout = 10000,rollbackFor = Exception.class,readOnly = true)
public class FaqsServiceImpl implements FaqsService {

    @Autowired
    private FaqsMapper faqsMapper;

    @Override
    public List<Faqs> findBykey(String key) {
        Condition condition = new Condition();
        condition.setKey(key);
        return faqsMapper.selectByCondition(condition);
    }

    @Override
    public List<Faqs> findAll() {
        return faqsMapper.selectByCondition(new Condition());
    }

    @Override
    @Transactional(readOnly = false)
    public void add(Faqs faqs) {
        faqsMapper.insert(faqs);
    }

    @Override
    public Faqs findByTitle(String title) {
        Condition condition = new Condition();
        condition.setTitle(title);
        List<Faqs> faqsList = faqsMapper.selectByCondition(condition);
        return faqsList.size()>0 ? faqsList.get(0):null;
    }

    @Override
    public Faqs findById(Long id) {
        Condition condition = new Condition();
        condition.setId(id);
        List<Faqs> faqsList = faqsMapper.selectByCondition(condition);
        return faqsList.size()>0 ? faqsList.get(0):null;
    }
}
